<?php
   class GoodsAction extends CommonAction{
   	/*  public function _filter(&$map)
   	 {
   	 	$map['subname']=Array('like');
   	 } */
   	//判断商品名称是否唯一
   	public function _before_insert(){
   		$model = M('Goods');
   		$Goods = $model->getByGoodsname($_POST ['goodsname']);
   		if ($Goods) {
   			$this->ajaxReturn ( '0', '该商品名称已经存在!', '300' );
   		}
   	}
   	
   	public function _before_update(){
   		$model = M('Goods');
   		$id = $_REQUEST['id'];
   		$Goods = $model->getByGoodsname($_POST ['goodsname']);
   		if ($Goods&&$Goods['id']!==$id) {
   			$this->ajaxReturn ( '0', '该商品名称已经存在!', '300' );
   		}
   	}
   }
?>